from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

def generate_launch_description():
    # 声明参数
    vehicle_id_arg = DeclareLaunchArgument(
        'vehicle_id',
        default_value="1",
        description='Vehicle ID.'
    )

    uav_namespace_arg = DeclareLaunchArgument(
        'uav_namespace',
        default_value='uav_swarms',
        description='Namespace for UAV swarms.'
    )

    vehicle_type_arg = DeclareLaunchArgument(
        'vehicle_type',
        default_value='drone',
        description='Type of vehicle.'
    )

    vehicle_num_arg = DeclareLaunchArgument(
        'vehicle_num',
        default_value="3",
        description='Number of vehicles.'
    )

    # 创建节点
    communication_multirotor_node = Node(
        package="uav_swarms",
        executable="CoordinateConform_node",
        name="CoordinateConform_node",
        output="screen",
        emulate_tty=True,
        parameters=[
            {"uav_namespace": LaunchConfiguration('uav_namespace')},
            {"vehicle_id": LaunchConfiguration('vehicle_id')},
            {"vehicle_num": LaunchConfiguration('vehicle_num')},
            {"vehicle_type": LaunchConfiguration('vehicle_type')},
        ]
    )

    # 创建并返回 LaunchDescription
    return LaunchDescription([
        vehicle_id_arg,
        uav_namespace_arg,
        vehicle_type_arg,
        vehicle_num_arg,
        communication_multirotor_node
    ])
